﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.BLL;



namespace WebApplication
{
    public partial class SearchPageTest : System.Web.UI.Page
    {
        public static int PageCount = 0;
        Search_Cust_Info ent = new Search_Cust_Info();
        Search_Cust_InfoBLL bll = new Search_Cust_InfoBLL();
        public static List<Search_Result> list = new List<Search_Result>();

        protected void Page_Load(object sender, EventArgs e)
        { 
           

            if (!IsPostBack)
            {
                ent = Session["SearchString"] as Search_Cust_Info;
                if (ent != null)
                {
                    #region
                    //Response.Write(ent.CustomerName + ":CustomerName<br>");
                    //Response.Write(ent.CustomerID + ":CustomerID<br>");
                    //Response.Write(ent.CustomerType + ":CustomerType<br>");
                    //Response.Write(ent.MemberShipSince + ":MemberShipSince<br>");
                    //Response.Write(ent.MemberShipStatus + ":MemberShipStatus<br>");
                    //Response.Write(ent.BrandName + ":BrandName<br>");
                    //Response.Write(ent.CustomerIntroduction + ":CustomerIntroduction<br>");
                    //Response.Write(ent.NoOfEmployee + ":NoOfEmployee<br>");
                    //Response.Write(ent.YearEstablished + ":YearEstablished<br>");
                    //Response.Write(ent.BR + ":BR<br>");
                    //Response.Write(ent.HKIDPassportNo + ":HKIDPassportNo<br>");
                    //Response.Write(ent.GC + ":GC<br>");
                    //Response.Write(ent.VIP + ":VIP<br>");
                    //Response.Write(ent.HQLocatedInHk + ":HQLocatedInHk<br>");
                    //Response.Write(ent.Address + ":Address<br>");
                    //Response.Write(ent.Continent + ":Continent<br>");
                    //Response.Write(ent.Country + ":Country<br>");
                    //Response.Write(ent.Position + ":Position<br>");
                    //Response.Write(ent.Email + ":Email<br>");
                    //Response.Write(ent.EmailUnsubscribe + ":EmailUnsubscribe<br>");
                    //Response.Write(ent.Fax + ":Fax<br>");
                    //Response.Write(ent.Fax_IsDNC + ":Fax_IsDNC<br>");
                    //Response.Write(ent.FaxUnsubscribe + ":FaxUnsubscribe<br>");
                    //Response.Write(ent.Tel + ":Tel<br>");
                    //Response.Write(ent.Tel_IsDNC + ";Tel_IsDNC<br>");
                    //Response.Write(ent.Tel_IsSubscribe + ":Tel_IsSubscribe<br>");
                    //Response.Write(ent.ContactPersonName + ";ContactPersonName<br>");
                    //Response.Write(ent.Salutation + ";Salutation<br>");
                    //Response.Write(ent.CommitteeType + ":CommitteeType<br>");
                    //Response.Write(ent.CommitteePosition + ":CommitteePosition<br>");
                    //Response.Write(ent.YearTerm + ":YearTerm<br>");
                    //Response.Write(ent.ProductSpecifictions + ":ProductSpecifictions<br>");
                    //Response.Write(ent.MarketProSpecifications + ":MarketProSpecifications<br>");
                    //Response.Write(ent.BranchName + ":BranchName<br>");
                    //Response.Write(ent.Attribute + ":Attribute<br>");
                    //Response.Write(ent.JobNaturexdcc + ":JobNaturexdcc<br> ");
                    //Response.Write(ent.BusinessNatur + ":BusinessNatur<br>");
                    //Response.Write(ent.ProductCategory + ":ProductCategory<br>");
                    //Response.Write(ent.MainMarket + "MainMarket<br>");
                    #endregion
                    list = bll.GetListByEntity(ent);                    
                    PageCount = list.Count();
                    CountAll.Text = PageCount.ToString(); 
                    List<Search_Result> list2 = list.Take(100).ToList();
                    Session["SeachResule"] = list;
                    PagerContrl.PageSize = 100; //15
                    PagerContrl.RecordCount = PageCount;
                    PagerContrl.CurrentPageIndex = 1;
                    GridView1.DataSource =list2;
                    GridView1.DataBind();
                }
                else {
                    Response.Redirect("Search.aspx"); 
                }

            }
        }
        protected void repBind(List<Search_Result> list,int val)
        {
            
            List<Search_Result> list2 = list.Skip(val).Take(100).ToList(); //Take(100)
            GridView1.DataSource = list2;
            GridView1.DataBind();
        }


        /// <summary>
        /// 分页控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void PagerContrl_PageChanged(object sender, EventArgs e)
        {            
            int CurrentPageIndex = (PagerContrl.CurrentPageIndex-1)*100; //*15
            if (list != null)
            {
                repBind(list, CurrentPageIndex);
            }
            else
            {
                list = Session["SeachResule"] as List<Search_Result>;
                repBind(list, CurrentPageIndex);
            }
        }
    }
}